var e = require("../@babel/runtime/helpers/typeof"), t = null, n = require("./md5.js");

function o(e) {
    var t = wx.getStorageSync("cacheRootConfig");
    if (t && null != t && t.hasOwnProperty(e)) return t[e];
}

function r(e) {
    return null != e && "" != e && (console.log(new Date(parseInt(e)).toDateString()), 
    new Date(parseInt(e)).toDateString() === new Date().toDateString() ? (console.log("当天"), 
    !0) : new Date(e) < new Date() && (console.log("以前的日期"), !1));
}

function a(e) {
    wx.setStorageSync("HadViewParseCount", e);
}

function i(e) {
    var t, o = function(e, t) {
        for (var n = "", o = e; o > 0; --o) n += t[Math.floor(Math.random() * t.length)];
        return n;
    }(32, "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ").toString(), r = (t = e + "&^@&^" + o, 
    n.md5(t)), a = {};
    return a.r = o, a.e = r, a;
}

function l() {
    return t.globalData.authTokenKey;
}

function c(e) {
    var t = wx.getStorageSync(e);
    if (console.log("timestamp" + t), null == t || "" == t) return "";
    var n = new Date(t), o = (n.getFullYear(), (n.getMonth() + 1 < 10 ? "0" + (n.getMonth() + 1) : n.getMonth() + 1) + "月" + (n.getDate() < 10 ? "0" + n.getDate() : n.getDate()) + "日" + n.getHours() + ":" + n.getMinutes() + ":" + n.getSeconds());
    return console.log(o), o;
}

function s(e) {
    return (e = e.toString())[1] ? e : "0" + e;
}

function u(e) {
    var n = t.globalData.appName, o = t.globalData.appVersion, r = "&app=" + n + "&ir=0&v=" + o;
    -1 == e.indexOf("?") && (r = "?" == e.slice(-"?".length) ? "app=" + n + "&ir=0&v=" + o : "?app=" + n + "&ir=0&v=" + o);
    var a = l(), i = wx.getStorageSync(a);
    return null == i && (i = ""), r = r.concat("&token=" + i), wx.getSystemInfo({
        success: function(t) {
            r = (r = (r = (r = r.concat("&model=" + encodeURI(t.model))).concat("&lang=" + encodeURI(t.language))).concat("&osn=Weixin&osv=" + encodeURI(t.version))).concat("&platform=" + encodeURI(t.platform)), 
            -1 == e.indexOf("screen_w") && (r = r.concat("&screen_w=750")), -1 == e.indexOf("screen_h") && (r = r.concat("&screen_h=1334"));
        }
    }), r;
}

function g(e, t) {
    e = e.split("."), t = t.split(".");
    for (var n = Math.max(e.length, t.length); e.length < n; ) e.push("0");
    for (;t.length < n; ) t.push("0");
    for (var o = 0; o < n; o++) {
        var r = parseInt(e[o]), a = parseInt(t[o]);
        if (r > a) return 1;
        if (r < a) return -1;
    }
    return 0;
}

function p(e) {
    var t = e.app_id, n = e.url, o = e.type;
    if (console.log(n), console.log(o), "app" == o && null != t && "" != t) wx.navigateToMiniProgram({
        appId: t,
        path: n,
        extraData: {
            foo: "bar"
        },
        envVersion: "release",
        success: function(e) {}
    }); else if ("f_imgurl" == o || "f_videourl" == o) {
        var r = JSON.stringify(e);
        wx.setStorageSync("TForwardItem", encodeURI(r)), wx.navigateTo({
            url: "/pages/forwardDetail/forwardDetail"
        });
    } else if ("imgurl" == o) {
        var a = e.imgURLs;
        if (null == a && (a = e.urls), null != a && "" != a) {
            var i = a.split(";");
            wx.previewImage({
                urls: i
            });
        }
    } else n && wx.navigateTo({
        url: n
    });
}

module.exports = {
    isToday: r,
    updateParseCount: function() {
        if (0 == r(wx.getStorageSync("ParseCountTimestamp"))) {
            var e = new Date().getTime();
            wx.setStorageSync("ParseCountTimestamp", e.toString()), wx.setStorageSync("ParseCount", 0), 
            a(0);
        }
        var t = wx.getStorageSync("ParseCount");
        t && null != t || (t = 0);
        wx.setStorageSync("ParseCount", t + 1);
    },
    getParseCount: function() {
        var e = wx.getStorageSync("ParseCount");
        e && null != e || (e = 0);
        return e;
    },
    updateViewParseLimit: a,
    isViewParseLimit: function() {
        var e = wx.getStorageSync("HadViewParseCount");
        e && null != e || (e = 0);
        if (0 == r(wx.getStorageSync("ParseCountTimestamp"))) {
            var t = new Date().getTime();
            wx.setStorageSync("ParseCountTimestamp", t.toString()), wx.setStorageSync("ParseCount", 0), 
            a(0);
        }
        return e;
    },
    getRootConfigValueByKey: o,
    getHost: function() {
        return t.globalData.host;
    },
    getLoginHost: function() {
        var e = t.globalData.loginHost, n = o("login_host");
        null != n && (e = n);
        return e;
    },
    getConfigPath: function() {
        return t.globalData.configPath;
    },
    parsePath: function() {
        return t.globalData.parsePath;
    },
    getAuthTokenKey: l,
    hasToken: function() {
        var e = wx.getStorageSync(l());
        if (null == e || "" == e) return !1;
        if (0 == e.indexOf("wx_")) return !1;
        return !0;
    },
    canMake: function(e) {
        if ("" == c(e)) return !0;
        var t = wx.getStorageSync(e);
        if (Date.parse(new Date()) < t) return !0;
        return !1;
    },
    syncRewardExpiredTime: function() {
        console.log("syncRewardExpiredTime");
        var e = wx.getStorageSync("ExpiredTime"), t = wx.getStorageSync("appConfig");
        if (null != t.reward_expiredTime) {
            var n = 60 * parseFloat(t.reward_expiredTime) * 60 * 1e3, o = Date.parse(new Date()) + n;
            console.log(o), e > o && wx.setStorageSync("ExpiredTime", o);
        }
    },
    setFirstExpiredTimeStamp: function(e, t) {
        var n = Date.parse(new Date()) + 60 * parseFloat(e) * 60 * 1e3;
        console.log(n), wx.setStorageSync(t, n);
    },
    setExpiredTimeStamp: function(e) {
        var t = Date.parse(new Date()), n = wx.getStorageSync("appConfig"), o = 23;
        null != n.reward_expiredTime && (o = n.reward_expiredTime);
        console.log("config.reward_expiredTime ：" + o);
        var r = t + 60 * parseFloat(o) * 60 * 1e3;
        console.log(r), wx.setStorageSync(e, r);
    },
    getExpiredFormatTime: c,
    setApp: function(e) {
        console.log("app:" + e), t = e;
    },
    formatTime: function(e) {
        var t = e.getFullYear(), n = e.getMonth() + 1, o = e.getDate(), r = e.getHours(), a = e.getMinutes(), i = e.getSeconds();
        return [ t, n, o ].map(s).join("/") + " " + [ r, a, i ].map(s).join(":");
    },
    json2Form: function(e) {
        var t = [];
        for (var n in e) t.push(encodeURIComponent(n) + "=" + encodeURIComponent(e[n]));
        return t.join("&");
    },
    formatPath: u,
    formatUrl: function(e) {
        var t = u(e);
        return e + t;
    },
    weightRand: function(e) {
        var t = [];
        for (var n in e) for (var o = 0; o < e[n].weight; o++) t.push(e[n].host);
        return t[Math.floor(Math.random() * t.length)];
    },
    encodingString: i,
    buildHeader: function(e) {
        null == e && (e = {});
        e["Auth-Token"] = wx.getStorageSync(l()), e.App = wx.getStorageSync("App");
        var t = i("normal");
        return e.r = t.r, e.d = t.e, e;
    },
    rAK: function(e) {
        console.log(e);
        var t = e.split(";"), n = t[Math.floor(Math.random() * t.length)];
        return console.log(n), n;
    },
    modeAD: function() {
        if (g(t.globalData.systemInfo.SDKVersion, "2.10.4") >= 0) {
            var e = wx.getStorageSync("appConfig"), n = 1;
            return null != e.mode_ad && (n = e.mode_ad), n;
        }
        return 0;
    },
    compareVersion: g,
    albumPermissionCheck: function(e, t) {
        g(wx.getSystemInfoSync().SDKVersion, "1.2.0") >= 0 ? wx.getSetting({
            success: function(n) {
                n.authSetting["scope.writePhotosAlbum"] ? e() : wx.authorize({
                    scope: "scope.writePhotosAlbum",
                    success: function() {
                        e();
                    },
                    fail: function() {
                        wx.showModal({
                            title: "相册权限",
                            confirmText: "设置权限",
                            content: t,
                            success: function(e) {
                                e.confirm ? (console.log("用户点击确定"), wx.openSetting({})) : e.cancel && console.log("用户点击取消");
                            }
                        });
                    }
                });
            },
            fail: function(t) {
                console.log(t), e();
            }
        }) : (wx.showModal({
            title: "提示",
            content: "当前微信版本过低，无法使用该功能，请升级到最新微信版本后重试。"
        }), e());
    },
    checkUpdateAPP: function() {
        var e = wx.getUpdateManager(), t = o("update_tips"), n = o("update_tips2");
        e.onCheckForUpdate(function(e) {
            console.log(e), 1 == e.hasUpdate && null != t && wx.showModal({
                title: "提示",
                content: t,
                success: function(e) {
                    e.confirm && wx.reLaunch({
                        url: "/pages/home/home"
                    });
                }
            });
        }), e.onUpdateReady(function() {
            null != n && ("10000" == n ? e.applyUpdate() : wx.showModal({
                title: "更新提示",
                content: n,
                success: function(t) {
                    t.confirm && e.applyUpdate();
                }
            }));
        }), e.onUpdateFailed(function() {});
    },
    globalTips: function() {
        var e = o("global_enforce");
        if (null == e || 0 == e) {
            var t = wx.getStorageSync("show_global_tips");
            if (console.log(t), 0 == t) return;
        }
        console.log("globalTips");
        var n = o("global_tips"), r = o("global_tips_btn"), a = o("global_cancel"), i = !0;
        0 == a && (i = !1);
        null == r && (r = "确定");
        var l = o("global_forward");
        null != n && (wx.setStorageSync("show_global_tips", 0), wx.showModal({
            title: "提示",
            content: n,
            confirmText: r,
            showCancel: i,
            success: function(e) {
                e.confirm && p(l);
            }
        }));
    },
    forwardItem: p
}, String.prototype.format = function(t) {
    return t = "object" === e(t) ? t : Array.prototype.slice.call(arguments, 0), f(this, t);
};

var f = function(t, n) {
    return n = "object" === e(n) ? n : Array.prototype.slice.call(arguments, 1), t.replace(/\{\{|\}\}|\{(\w+)\}/g, function(e, t) {
        return "{{" == e ? "{" : "}}" == e ? "}" : n[t];
    });
};

String.prototype.endsWith = function(e) {
    return this.slice(-e.length) == e;
}, String.prototype.replaceAll = function(e, t) {
    return this.split(e).join(t);
};